<?php
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
	
	$lang = $_SESSION['lang'];
	if (empty($lang) || $lang == "EN") {
		include "../value/value_en.php";
	} else if($lang == "VN") {
		include "../value/value_vn.php";
	}
	else {
		include "../value/value_kr.php";
	}

$arr=array();


$time='~';
if(isset($_REQUEST['vtime'])){
	$time= $_REQUEST['vtime'];
}

if (isset($_SESSION['listcontract'])) {
	$arr=$_SESSION['listcontract'];
	//include '../Classes/PHPExcel.php';
	/** Include path **/
	set_include_path(get_include_path() . PATH_SEPARATOR . 'ClassesExcel/');
	
	/** PHPExcel */
	require_once 'PHPExcel.php';
	
	/** PHPExcel_RichText */
	require_once 'PHPExcel/RichText.php';
	
	
	$filename ="export_contract.xls";
	
	$objPHPExcel = new PHPExcel();

	
	$styleArray = array(
		'font' => array(
			'bold' => true,
			'size' => 11,
		),
		'alignment' => array(
			'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
			'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
			'wrap' => true,
		),
		'borders' => array(
			'top' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'bottom' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'left' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'right' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
		),
		'fill' => array(
			'type' => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
			'rotation' => 90,
			'startcolor' => array(
				'argb' => 'FFA0A0A0',
			),
			'endcolor' => array(
				'argb' => 'FFFFFFFF',
			),
		),
	);
	$styleArray1 = array(
		'font' => array(
			'bold' => true,
			'size' => 11,
		),
		'alignment' => array(
			'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
			'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
			'wrap' => true,
		),
		'borders' => array(
			'top' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'bottom' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'left' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'right' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
		),
		
	);
	$styleArray2 = array(
			'alignment' => array(
			'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
			'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
			'wrap' => true,
		),
		'borders' => array(
			'top' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'bottom' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'left' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'right' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
		),
		
	);
	$styleArray3 = array(
			'alignment' => array(
			'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
			'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
			'wrap' => true,
		),
		'borders' => array(
			'top' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'bottom' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'left' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'right' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
		),
		
	);
	$styleArray4 = array(
			'alignment' => array(
			'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
			'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
			'wrap' => true,
		),
		'borders' => array(
			'top' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'bottom' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'left' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'right' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
		),
		
	);
	$styleArray5 = array(
		'alignment' => array(
			'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
			'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
			'wrap' => true,
		),
		'font' => array(
			'bold' => true,
			
		),
		'borders' => array(
			'top' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'bottom' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'left' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'right' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
		),
		
	);
	/*$objPHPExcel->getProperties()->setCreator('Matthew Casperson')
	->setLastModifiedBy('Matthew Casperson')
	->setTitle('Office 2007 XLSX Test Document')
	->setSubject('Office 2007 XLSX Test Document')
	->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.');
	
	
	$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial');
	$objPHPExcel->getDefaultStyle()->getFont()->setSize(8); */
	
	$objPHPExcel->setActiveSheetIndex(0);
	
	$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setName('Times New Roman');
	$objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(25);
	$objPHPExcel->getActiveSheet()->mergeCells('A1:J1');
	$objPHPExcel->getActiveSheet()->getStyle('A1')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->setCellValue('A1',$l_contract);
	

	$objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(25);
	$objPHPExcel->getActiveSheet()->mergeCells('A2:E2');
	$objPHPExcel->getActiveSheet()->getStyle('A2')->applyFromArray($styleArray3);
	$objPHPExcel->getActiveSheet()->getStyle('B2')->applyFromArray($styleArray3);
	$objPHPExcel->getActiveSheet()->getStyle('C2')->applyFromArray($styleArray3);
	$objPHPExcel->getActiveSheet()->getStyle('D2')->applyFromArray($styleArray3);
	$objPHPExcel->getActiveSheet()->getStyle('E2')->applyFromArray($styleArray3);
	$objPHPExcel->getActiveSheet()->setCellValue('A2',$l_signDay_contract.' : '.$time);

	$mtype=array($l_all,'개발','공사','물품','시설','용역','기타');
	
	$objPHPExcel->getActiveSheet()->getRowDimension('3')->setRowHeight(25);
	$objPHPExcel->getActiveSheet()->mergeCells('A3:C3');
	$objPHPExcel->getActiveSheet()->getStyle('A3')->applyFromArray($styleArray3);
	$objPHPExcel->getActiveSheet()->getStyle('B3')->applyFromArray($styleArray3);
	$objPHPExcel->getActiveSheet()->getStyle('C3')->applyFromArray($styleArray3);
	
	$objPHPExcel->getActiveSheet()->setCellValue('A3',$l_type_contract.' : '.$mtype[$_REQUEST['type']]);
	
	if ($_REQUEST['statusPayment']==-1)
		$statusPayment=$l_all;
	if ($_REQUEST['statusPayment']==0)
		$statusPayment=$l_complete;
	if ($_REQUEST['statusPayment']==1)
		$statusPayment=$l_uncomplete;
	$objPHPExcel->getActiveSheet()->mergeCells('D3:E3');
	$objPHPExcel->getActiveSheet()->getStyle('D3')->applyFromArray($styleArray3);
	$objPHPExcel->getActiveSheet()->getStyle('E3')->applyFromArray($styleArray3);

	
	$objPHPExcel->getActiveSheet()->setCellValue('D3',$l_statusPayment_contract.' : '.$statusPayment);
	
	
	$objPHPExcel->getActiveSheet()->getRowDimension('4')->setRowHeight(25);
	if($_REQUEST['cusname']!=""){
		$objPHPExcel->getActiveSheet()->mergeCells('A4:C4');
		$objPHPExcel->getActiveSheet()->getStyle('A4')->applyFromArray($styleArray3);
		$objPHPExcel->getActiveSheet()->getStyle('B4')->applyFromArray($styleArray3);
		$objPHPExcel->getActiveSheet()->getStyle('C4')->applyFromArray($styleArray3);
		
		$objPHPExcel->getActiveSheet()->setCellValue('A4',$l_nameCompany_contract.' : '.$_REQUEST['cusname']);
	}
	if($_REQUEST['nameProduct']!=""){
		$objPHPExcel->getActiveSheet()->mergeCells('D4:E4');
		$objPHPExcel->getActiveSheet()->getStyle('D4')->applyFromArray($styleArray3);
		$objPHPExcel->getActiveSheet()->getStyle('E4')->applyFromArray($styleArray3);
		
		$objPHPExcel->getActiveSheet()->setCellValue('D4',$l_nameProduct_contract.' : '.$_REQUEST['nameProduct']);
	}
	
	$objPHPExcel->getActiveSheet()->freezePane('A6');
	
	$objPHPExcel->getActiveSheet()->getRowDimension('5')->setRowHeight(25);
	 
	$objPHPExcel->getActiveSheet()->getStyle('A5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('A5',$l_no);
	
	
	$objPHPExcel->getActiveSheet()->getStyle('B5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('B5', $l_type_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('C5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('C5', $l_code_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('D5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('D5', $l_name_contract);
	
	
	$objPHPExcel->getActiveSheet()->getStyle('E5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('E5', $l_signDay_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('F5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('F5', $l_totalValue_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('G5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('G5', $l_prepaidMoney_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('H5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('H5', $l_otherMoney_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('I5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('I5', $l_statusPayment_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('J5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('J5', $l_signer_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('K5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('K5', $l_expectedDay_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('L5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('L5', $l_completeDay_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('M5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('M5', $l_area_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('N5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('N5', $l_placeDelivery_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('O5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('O')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('O5', $l_nameCompany_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('P5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('P')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('P5', $l_agencies_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('Q5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('Q5', $l_content_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('R5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('R')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('R5', $l_method_contract1);
	
	$objPHPExcel->getActiveSheet()->getStyle('S5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('S')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('S5', $l_provideGovernment_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('T5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('T')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('T5', $l_provide_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('U5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('U')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('U5', $l_method_contract2);
	
	$objPHPExcel->getActiveSheet()->getStyle('V5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('V')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('V5', $l_nameProduct_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('W5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('W')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('W5', $l_promotions_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('X5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('X')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('X5', $l_expireWarrantyDay_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('Y5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('Y')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('Y5', $l_agenciesCheck_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('Z5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('Z')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('Z5', $l_methodsPayment_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('AA5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('AA')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('AA5', $l_methodsDelivery_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('AB5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('AB')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('AB5', $l_classification_contract);
	
	$objPHPExcel->getActiveSheet()->getStyle('AC5')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('AC')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('AC5', $l_comment);
	
	$soluong= count($arr);
	$key=6;
	$FORMAT_DATE_YYYYMMDD2             = 'yyyy-mm-dd';
	$FORMAT_DATE_YYYYMMDD              = 'yy-mm-dd';
	$FORMAT_DATE_DDMMYYYY              = 'dd/mm/yy';
	$FORMAT_DATE_DMYSLASH              = 'd/m/y';
	$FORMAT_DATE_DMYMINUS              = 'd-m-y';
	$FORMAT_DATE_DMMINUS               = 'd-m';
	$FORMAT_DATE_MYMINUS               = 'm-y';
	$FORMAT_DATE_XLSX14                = 'mm-dd-yy';
	$FORMAT_DATE_XLSX15                = 'd-mmm-yy';
	$FORMAT_DATE_XLSX16                = 'd-mmm';
          if($soluong>0){
           		$vitri=1;
           		$tong1=0;
           		$tong2=0;
           		$stong1=0;
				$stong2=0;
           		foreach($arr as $temp=>$value1){
           			$dem=0;
	           			foreach($value1 as $value=>$mgiatri){	
	           				$tong1+=$mgiatri[4];
	           				$tong2+=$mgiatri[5];
		           			$objPHPExcel->getActiveSheet()->getRowDimension($key)->setRowHeight(25);
							$objPHPExcel->getActiveSheet()->getStyle('A'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('A'.$key, $vitri);
									
							$objPHPExcel->getActiveSheet()->getStyle('B'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('B'.$key, $mgiatri[0]);
									
							$objPHPExcel->getActiveSheet()->getStyle('C'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('C'.$key, $mgiatri[1]);
									
							$objPHPExcel->getActiveSheet()->getStyle('D'.$key)->applyFromArray($styleArray3);
							$objPHPExcel->getActiveSheet()->setCellValue('D'.$key, $mgiatri[2]);
									
									
							$objPHPExcel->getActiveSheet()->getStyle('E'.$key)->applyFromArray($styleArray2);
							//$objPHPExcel->getActiveSheet()->getStyle('E'.$key)->getNumberFormat()->setFormatCode($FORMAT_DATE_YYYYMMDD);
							$objPHPExcel->getActiveSheet()->setCellValue('E'.$key,$mgiatri[3]);
								
							$objPHPExcel->getActiveSheet()->getStyle('F'.$key)->applyFromArray($styleArray4);
							$objPHPExcel->getActiveSheet()->getStyle('F'.$key)->getNumberFormat()->setFormatCode('#,##0');
							$objPHPExcel->getActiveSheet()->setCellValue('F'.$key, $mgiatri[4]);
									
							$objPHPExcel->getActiveSheet()->getStyle('G'.$key)->applyFromArray($styleArray4);
							$objPHPExcel->getActiveSheet()->getStyle('G'.$key)->getNumberFormat()->setFormatCode('#,##0');
							$objPHPExcel->getActiveSheet()->setCellValue('G'.$key, $mgiatri[5]);
									
							$objPHPExcel->getActiveSheet()->getStyle('H'.$key)->applyFromArray($styleArray4);
							$objPHPExcel->getActiveSheet()->getStyle('H'.$key)->getNumberFormat()->setFormatCode('#,##0');
							$objPHPExcel->getActiveSheet()->setCellValue('H'.$key, $mgiatri[6]);
							
							if($mgiatri[7]==1){
								$objPHPExcel->getActiveSheet()->getStyle('I'.$key)->applyFromArray($styleArray2);
								$objPHPExcel->getActiveSheet()->setCellValue('I'.$key, $l_complete);
							}else{
								$objPHPExcel->getActiveSheet()->getStyle('I'.$key)->applyFromArray($styleArray2);
								$objPHPExcel->getActiveSheet()->setCellValue('I'.$key, $l_uncomplete);
							}
		
							$objPHPExcel->getActiveSheet()->getStyle('J'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('J'.$key, $mgiatri[8]);
							
							$objPHPExcel->getActiveSheet()->getStyle('K'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('K'.$key, $mgiatri[9]);
							
							$objPHPExcel->getActiveSheet()->getStyle('L'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('L'.$key, $mgiatri[10]);
							
							$objPHPExcel->getActiveSheet()->getStyle('M'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('M'.$key, $mgiatri[11]);
							
							$objPHPExcel->getActiveSheet()->getStyle('N'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('N'.$key, $mgiatri[12]);
							
							$objPHPExcel->getActiveSheet()->getStyle('O'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('O'.$key, $mgiatri[13]);
							
							$objPHPExcel->getActiveSheet()->getStyle('P'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('P'.$key, $mgiatri[14]);
							
							$objPHPExcel->getActiveSheet()->getStyle('Q'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('Q'.$key, $mgiatri[15]);
							
							$objPHPExcel->getActiveSheet()->getStyle('R'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('R'.$key, $mgiatri[16]);
							
							$objPHPExcel->getActiveSheet()->getStyle('S'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('S'.$key, $mgiatri[17]);
							
							$objPHPExcel->getActiveSheet()->getStyle('T'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('T'.$key, $mgiatri[18]);
							
							$objPHPExcel->getActiveSheet()->getStyle('U'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('U'.$key, $mgiatri[19]);
							
							$objPHPExcel->getActiveSheet()->getStyle('V'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('V'.$key, $mgiatri[20]);
							
							$objPHPExcel->getActiveSheet()->getStyle('W'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('W'.$key, $mgiatri[21]);
							
							$objPHPExcel->getActiveSheet()->getStyle('X'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('X'.$key, $mgiatri[22]);
							
							$objPHPExcel->getActiveSheet()->getStyle('Y'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('Y'.$key, $mgiatri[23]);
							
							$objPHPExcel->getActiveSheet()->getStyle('Z'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('Z'.$key, $mgiatri[24]);
							
							$objPHPExcel->getActiveSheet()->getStyle('AA'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('AA'.$key, $mgiatri[25]);
							
							$objPHPExcel->getActiveSheet()->getStyle('AB'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('AB'.$key, $mgiatri[26]);
							
							$objPHPExcel->getActiveSheet()->getStyle('AC'.$key)->applyFromArray($styleArray2);
							$objPHPExcel->getActiveSheet()->setCellValue('AC'.$key, $mgiatri[27]);
		
				            $vitri++;
				            $key++;  
				            $dem++;
	           			}
           			
           			$objPHPExcel->getActiveSheet()->getRowDimension($key)->setRowHeight(25);
           			$objPHPExcel->getActiveSheet()->mergeCells('A'.$key.':E'.$key);
					$objPHPExcel->getActiveSheet()->getStyle('A'.$key)->applyFromArray($styleArray1);
					$objPHPExcel->getActiveSheet()->getStyle('B'.$key)->applyFromArray($styleArray1);
					$objPHPExcel->getActiveSheet()->getStyle('C'.$key)->applyFromArray($styleArray1);
					$objPHPExcel->getActiveSheet()->getStyle('D'.$key)->applyFromArray($styleArray1);
					$objPHPExcel->getActiveSheet()->getStyle('E'.$key)->applyFromArray($styleArray1);
					
					if($_REQUEST['typeSearch']=="ngay"){
						$objPHPExcel->getActiveSheet()->setCellValue('A'.$key,$l_days.': '.$temp.' - '.$l_co.' : '.$dem.' '.$l_contract);
					}else{
						$objPHPExcel->getActiveSheet()->setCellValue('A'.$key,$l_month.': '.$temp.' - '.$l_co.' : '.$dem.' '.$l_contract);
					}
					$objPHPExcel->getActiveSheet()->getStyle('F'.$key)->applyFromArray($styleArray5);
					$objPHPExcel->getActiveSheet()->getStyle('F'.$key)->getNumberFormat()->setFormatCode('#,##0');
					$objPHPExcel->getActiveSheet()->setCellValue('F'.$key, $tong1);
					
					$objPHPExcel->getActiveSheet()->getStyle('G'.$key)->applyFromArray($styleArray5);
					$objPHPExcel->getActiveSheet()->getStyle('G'.$key)->getNumberFormat()->setFormatCode('#,##0');
					$objPHPExcel->getActiveSheet()->setCellValue('G'.$key, $tong2);
					$stong1+=$tong1;
					$stong2+=$tong2;
					$tong1=0;
					$tong2=0;
           			$key++;
           		}
           		
           			$objPHPExcel->getActiveSheet()->getRowDimension($key)->setRowHeight(25);
           			$objPHPExcel->getActiveSheet()->mergeCells('A'.$key.':E'.$key);
					$objPHPExcel->getActiveSheet()->getStyle('A'.$key)->applyFromArray($styleArray1);
					$objPHPExcel->getActiveSheet()->getStyle('B'.$key)->applyFromArray($styleArray1);
					$objPHPExcel->getActiveSheet()->getStyle('C'.$key)->applyFromArray($styleArray1);
					$objPHPExcel->getActiveSheet()->getStyle('D'.$key)->applyFromArray($styleArray1);
					$objPHPExcel->getActiveSheet()->getStyle('E'.$key)->applyFromArray($styleArray1);
					
					
					$objPHPExcel->getActiveSheet()->setCellValue('A'.$key,$l_tongdon);
					
					$objPHPExcel->getActiveSheet()->getStyle('F'.$key)->applyFromArray($styleArray5);
					$objPHPExcel->getActiveSheet()->getStyle('F'.$key)->getNumberFormat()->setFormatCode('#,##0');
					$objPHPExcel->getActiveSheet()->setCellValue('F'.$key, $stong1);
					
					$objPHPExcel->getActiveSheet()->getStyle('G'.$key)->applyFromArray($styleArray5);
					$objPHPExcel->getActiveSheet()->getStyle('G'.$key)->getNumberFormat()->setFormatCode('#,##0');
					$objPHPExcel->getActiveSheet()->setCellValue('G'.$key, $stong2);

           }
	
	include 'PHPExcel/IOFactory.php';
	
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
	header("Cache-Control: no-store, no-cache, must-revalidate");
	header("Cache-Control: post-check=0, pre-check=0", false);
	header("Pragma: no-cache");
	header("Content-type: application/vnd.ms-excel");
	header('Content-Disposition: attachment; filename=' . $filename);
	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
	$objWriter->save('php://output');
}
exit;

?>

